package com.cyh.ebpttoolswar.toolswar.controller;

import com.cyh.ebpttoolswar.toolswar.entity.City;
import com.cyh.ebpttoolswar.toolswar.repository.CityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CityController {


    @Autowired
    private CityRepository cityRepository;


    @GetMapping(value = "saveCity")
    public String saveCity(String cityName,String cityIntroduce){
        City city = new City(cityName,cityIntroduce);
        cityRepository.save(city);
        return "success";
    }

//    @GetMapping(value = "deleteCity")
//    public String deleteCity(int cityId){
//        cityRepository.delete(cityId);
//        return "success";
//    }

    @GetMapping(value = "updateCity")
    public String updateCity(int cityId,String cityName,String cityIntroduce){
        City city = new City(cityId,cityName,cityIntroduce);
        cityRepository.save(city);
        return "success";
    }


//    @GetMapping(value = "getCityById")
//    public City getCityById(int cityId){
//        City city = cityRepository.findOne(cityId);
//        return city;
//    }
}
